package utils

var Res *Result

// Result 结构体
type Result struct {
	Success bool        `json:"success"`
	Code    int         `json:"code"`
	Msg     string      `json:"msg"`
	Data    interface{} `json:"data"`
}

// OK 成功
func (r *Result) OK(msg string, code int, data ...interface{}) *Result {
	return &Result{
		Success: true,
		Code:    code,
		Msg:     msg,
		Data:    data[0],
	}
}

// OK 成功
func OK() *Result {
	return &Result{
		Success: true,
		Code:    200,
		Msg:     "成功",
		Data:    nil,
	}
}

func JSON() *Result {
	return &Result{
		Success: true,
		Code:    200,
		Msg:     "成功",
		Data:    nil,
	}
}

func JSONData(data interface{}) *Result {
	return &Result{
		Success: true,
		Code:    200,
		Msg:     "成功",
		Data:    data,
	}
}

// Fail 失败
func Fail(msg string, code int) *Result {
	return &Result{
		Success: true,
		Code:    code,
		Msg:     msg,
		Data:    nil,
	}
}

var ResP *Page

type Page struct {
	Total int64       `json:"total"`
	List  interface{} `json:"list"`
}

func (p *Page) ResponsePagination(count int64, list interface{}) *Page {
	return &Page{
		Total: count,
		List:  list,
	}
}
